//
//  JZHChatViewController.m
//  极致荟
//
//  Created by hetao on 14-5-15.
//  Copyright (c) 2014年 mac. All rights reserved.
//

#import "JZHChatViewController.h"
#import "JZHMyChatTableViewCell.h"
#import "JZFrendeChatHTableViewCell.h"
#import "JZHDetailsViewController.h"
#import "Expression.h"
#import "JZHSocket.h"
#import "Rrcorder.h"
#import "NoteDao.h"
#import "OtherUsersDao.h"
#import "JZHContactsViewController.h"
@interface JZHChatViewController ()
{
    Expression *keyview;
    JZHSocket *socket;
    NSArray *dataarr;
    UIPanGestureRecognizer *pan;
    
    NSDictionary *palydic;
}
- (IBAction)pusmp:(id)sender;
@property (weak, nonatomic) IBOutlet UIView *tishi;
@property (weak, nonatomic) IBOutlet UITableView *table;
@end

@implementation JZHChatViewController
- (id)initOuser:(OtherUsers *)ouser Recommend:(id)recommend
{
    JZHChatViewController *jzh=[[JZHChatViewController alloc]init];
    jzh.fuser=ouser;
    jzh.recommend=recommend;
    return jzh;
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidAppear:(BOOL)animated
{
   
    [super viewDidAppear:animated];
    if(self.recommend!=nil && [self.recommend isKindOfClass:[OtherUsers class]])
    {
        OtherUsers *ouser=(OtherUsers *)self.recommend;
        NSString *message=[NSString stringWithFormat:@"确定发送%@的名片到当前聊天",ouser.name];
        [[[UIAlertView alloc] initWithTitle:nil message:message delegate:self cancelButtonTitle:@"否" otherButtonTitles:@"是", nil] show];
    }
  
}

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    [self.toolView setHidden:YES];
    [keyview hidden];
    [OtherUsersDao dorpNuber:self.fuser];
}
- (void)viewDidLoad
{
    [super viewDidLoad];
    [self ToUpdateView];
    [self.shuohuabut.layer  setCornerRadius:6.0];
    [self.shuohuabut.layer setBorderWidth:1];
    [self.shuohuabut.layer setBorderColor:[[UIColor grayColor] CGColor]];
    [self.conntentext setReturnKeyType:UIReturnKeySend];
    
    if(!pan)
    {
        pan=[[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(shouzipan:)];
        [self.view addGestureRecognizer:pan];
    }
    
      keyview= [Expression shareExpression:self.conntentext viewconncrerll:self];
    [self.conntentext setDelegate:self];
    UITapGestureRecognizer *tap=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(clike:)];
    [self.table addGestureRecognizer:tap];
     //[self.conntentext setContentOffset:CGPointMake(0, -15)];
    //设置左侧按钮
    UIButton *leftButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 12, 20)];
    [leftButton addTarget:self action:@selector(leftDrawerButtonPress:) forControlEvents:UIControlEventTouchUpInside];
    [leftButton setImage:[UIImage imageNamed:@"返回"] forState:UIControlStateNormal];
    UIBarButtonItem *leftBarButton = [[UIBarButtonItem alloc] initWithCustomView:leftButton];
    self.navigationItem.leftBarButtonItem = leftBarButton;
    if(self.fuser.bname.length!=0)
    {
         self.navigationItem.title=self.fuser.bname;
    }else
    {
        self.navigationItem.title=self.fuser.name;
    }

    if(OSVersionIsAtLeastiOS7>=7.0)
    {
        self.automaticallyAdjustsScrollViewInsets=NO;
    }
    
    //添加观察者
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notkey:) name:UIKeyboardWillChangeFrameNotification object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(shoumessage:) name:SENDMESSAGE object:nil];
    
    //设置右侧导航按钮
    UIButton *rightButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 30, 44)];
    [rightButton addTarget:self action:@selector(rightDrawerButtonPress:) forControlEvents:UIControlEventTouchUpInside];
    [rightButton setImage:[UIImage imageNamed:@"123@2x@x2"] forState:UIControlStateNormal];
    UIBarButtonItem *rightBarButton = [[UIBarButtonItem alloc] initWithCustomView:rightButton];
    self.navigationItem.rightBarButtonItem = rightBarButton;
    socket= [JZHSocket deful:self];
}

- (void)leftDrawerButtonPress:(UIButton *)but
{
    [self.navigationController popToRootViewControllerAnimated:YES];
}

- (void)rightDrawerButtonPress:(UIButton *)but
{
    [self.navigationController pushViewController:[[JZHDetailsViewController alloc]initOthUser:self.fuser] animated:YES];
}
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
#pragma mark--------UITextView代理--------
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
{
   
    if([text isEqualToString:@"\n"])
    {
        if(![textView.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]].length==0)
        {
            [self senderMessge:textView.text tyep:TEXT];
            textView.text=@"";
            [self aoutTextViewFram];
            [self.conntentext setContentOffset:CGPointMake(0, 0)];
        }
        return NO;
    }
      [self aoutTextViewFram];
    return YES;
}

///试听-发送
- (IBAction)senderlu:(id)sender
{
    self.playview.hidden=YES;
    [[Rrcorder defule] stoprecorder];
    [self updataVoid];
    
}
///发送消息
- (void)senderMessge:(NSString *)connten tyep:(NoteType)type
{
    Note *note=[[Note alloc]init];
    note.senderId=[User defuceUser].userId;
    note.recipientId=_fuser.userId;
    note.noteType=type;
    if(type==VOICE)
    {
        note.vodeleng=[[palydic objectForKey:@"time"] stringValue] ;
    }else
    {
        note.vodeleng=@"no";
    }
    note.content=connten;
    note.noteDate=[NSDate date];

    //消息内容，包含消息类型，用/messageType 划分开
     NSString *messagetext=[NSString stringWithFormat:@"%d-%@messageType%@",type,note.vodeleng,note.content];
    NSDictionary *contents=[[NSDictionary alloc] initWithObjectsAndKeys:[NSNumber numberWithInt:type],@"messageType",note.content,@"text",note.vodeleng,@"vodeleng", nil];
    NSDictionary *datadic=[[NSDictionary alloc]initWithObjectsAndKeys:[NSNumber numberWithInt:note.senderId],@"push",[NSNumber numberWithInt:note.recipientId], @"accept",contents,@"content",nil ];
   
    NSDictionary *messgedic=[[NSDictionary alloc]initWithObjectsAndKeys:@"sendMessage",@"type",datadic,@"data", nil];
    
    NSData *jsondata=[NSJSONSerialization dataWithJSONObject:messgedic options:NSJSONWritingPrettyPrinted error:nil];
    NSString *json=[[NSString alloc]initWithData:jsondata encoding:NSUTF8StringEncoding];
     //json=[json stringByReplacingOccurrencesOfString:@"\n" withString:@""];
    
    [socket send:json];
    
    [NoteDao insertData:note];
        self.fuser.note=note;
    
    [OtherUsersDao NoteMessage:self.fuser];
    [self ToUpdateView];
}

///更新聊天界面
- (void)ToUpdateView
{

    dataarr=[NoteDao selectData:_fuser.userId];
    if(dataarr.count!=0)
    {
        NSIndexPath *indexPath = [NSIndexPath indexPathForRow:dataarr.count  inSection:0];
        [self.table reloadData];
        [self.table scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionBottom animated:YES];
    }else
    {
        [self.table reloadData];
    }
   
    
}


///输入框文字适配
- (void)aoutTextViewFram
{
  CGSize  size= [self.conntentext sizeThatFits:CGSizeMake(self.conntentext.frame.size.width, 0)];
    
    //NSLog(@"%f  %f",size.width,size.height);
    if(size.height-18>self.conntentext.frame.size.height && size.height<70)
    {
        [self.conntentext setContentOffset:CGPointMake(0, self.conntentext.contentSize.height-self.conntentext.frame.size.height+8)];
        [UIView animateWithDuration:0.2 animations:^{
            [self.expView setFrame:CGRectMake(0, self.expView.frame.origin.y-size.height+22, 320, 46+size.height-22)];
            [self.conntentext sizeToFit];
        }];
        
        return;
    }
    if(self.conntentext.frame.size.height>size.height)
    {
        [self.conntentext setContentOffset:CGPointMake(0, self.conntentext.contentSize.height-self.conntentext.frame.size.height+8)];
        [UIView animateWithDuration:0.2 animations:^{
            [self.expView setFrame:CGRectMake(0, self.view.frame.size.height-self.expView.frame.size.height+22 , 320, 46)];
        }];
        return;
    }
//    NSLog(@"%f",self.conntentext.contentOffset.y);
//    [self.conntentext setContentOffset:CGPointMake(0, self.conntentext.contentSize.height-self.conntentext.frame.size.height)];
    //[self.conntentext setFrame:CGRectMake(self.conntentext.frame.origin.x, self.conntentext.frame.origin.y, self.conntentext.frame.size.width, size.height)];
}

///点击手势
- (void)clike:(UITapGestureRecognizer *)tap
{
    [[UIApplication sharedApplication].keyWindow endEditing:YES];
    [keyview hidden];
    [UIView animateWithDuration:.3 animations:^{
         [self.toolView setFrame:CGRectMake(0, HEIGHT+20, self.toolView.frame.size.width, self.toolView.frame.size.height)];
        [self.view setCenter:CGPointMake(160, self.view.frame.size.height/2)];
    }];
    self.toolbut.selected=NO;
    self.expression.selected=NO;
    [self.toolView setHidden:YES];
    
}
///滑动手势
- (void)shouzipan:(UIPanGestureRecognizer *)sender
{
    if(self.table.userInteractionEnabled)
    {
        return;
    }
    if(sender.state==UIGestureRecognizerStateChanged)
    {
        if([sender translationInView:self.view].y*-1>20)//手指是否上滑
        {
            if([[Rrcorder defule] isplay])
            {
                palydic=[[Rrcorder defule] recorderStop];
                
            }
            
            self.operation.hidden=NO;
          
            //坐标系转换
            CGPoint ppoint=[self.oplaybut convertPoint:self.oplaybut.center toView:self.view];
            CGPoint dpoint=[self.odorpbut convertPoint:self.odorpbut.center toView:self.view];
           
            float ppwidth=self.oplaybut.frame.size.width;
            //是否移动到试听按钮
            if([sender locationInView:self.view].x>=ppoint.x-ppwidth/2 && [sender locationInView:self.view].x<=ppoint.x+ppwidth/2)
            {
                if([sender locationInView:self.view].y>=ppoint.y-ppwidth/2 && [sender locationInView:self.view].y<=ppoint.y+ppwidth/2)
                {
                    self.oplaybut.selected=YES;
                    self.odorpbut.selected=NO;
                }else
                {
                    self.oplaybut.selected=NO;
                }
            }else
            {
                self.oplaybut.selected=NO;
            }
            
            
            //是否移动到取消发送按钮
            if([sender locationInView:self.view].x>=dpoint.x/2-ppwidth/2 && [sender locationInView:self.view].x<=dpoint.x/2+ppwidth/2+20)
            {
                if([sender locationInView:self.view].y>=dpoint.y-ppwidth/2 && [sender locationInView:self.view].y<=dpoint.y+ppwidth/2)
                {
                    self.odorpbut.selected=YES;
                    self.oplaybut.selected=NO;
                }else
                {
                    self.odorpbut.selected=NO;
                }
            }else
            {
                self.odorpbut.selected=NO;
            }
            
        }
    }
    
    if(sender.state==UIGestureRecognizerStateEnded)//当手指离开时
    {
        if(self.oplaybut.selected)//当用户选择试听
        {
            self.operation.hidden=YES;
            self.playview.hidden=NO;
            //[pan setEnabled:NO];
            [self.playst setTitle:[NSString stringWithFormat:@"%@''",[palydic objectForKey:@"time"]] forState:UIControlStateNormal];
            self.operation.hidden=YES;
            
            return;
        }
        
        self.operation.hidden=YES;
        [self endLu:self.shuohuabut];
        
        
    }
    
}
- (IBAction)begenLu:(UIButton *)sender//按下开始录音
{
    [self.table setUserInteractionEnabled:NO];
    [[Rrcorder defule] recorderStater];
    
}
- (IBAction)endLu:(UIButton *)sender
{
    palydic= [[Rrcorder defule] recorderStop];//松开结束录音
    [self.table setUserInteractionEnabled:YES];
    if([[palydic objectForKey:@"time"] intValue]<1)
    {
        self.tishi.hidden=NO;
        [UIView animateWithDuration:.5 animations:^{
            [self.tishi setBackgroundColor:[UIColor grayColor]];
        } completion:^(BOOL finished) {
            self.tishi.hidden=YES;
            [self.tishi setBackgroundColor:[UIColor clearColor]];
        }];
    }else
    {
        [self updataVoid];
    }
    
}

//播放声音
- (IBAction)stplaybut:(id)sender
{
    NSData *data=[palydic objectForKey:@"data"];
    [[Rrcorder defule] recorderplayerData:data];
}

- (IBAction)showluying:(UIButton *)sender
{
    if(sender.selected)
    {
        self.shuohuabut.hidden=YES;
        self.conntentext.hidden=NO;
        sender.selected=NO;
        [self aoutTextViewFram];
        [self.conntentext becomeFirstResponder];
       
    }else
    {
        self.shuohuabut.hidden=NO;
        self.conntentext.hidden=YES;
        sender.selected=YES;
        
        [self.expView setFrame:CGRectMake(0, self.view.frame.size.height-46, 320, 46)];
         [[UIApplication sharedApplication].keyWindow endEditing:YES];
    }
}


#pragma mark-------TableView代理----------
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section;

{
    return dataarr.count+1;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    JZHMyChatTableViewCell *cell=[[[NSBundle mainBundle] loadNibNamed:@"JZFrendeChatHTableViewCell" owner:self options:nil] objectAtIndex:0];
    if(indexPath.row==0)
    {
        
        CGFloat hige=self.table.frame.size.height;
        for(int i=0;i<dataarr.count;i++)
        {
            Note *note=dataarr[i];
            hige-=[cell addCellData:note user:[User defuceUser]];
            if(hige<=0)
            {
                return 0;
            }
        }
        return hige;
    }else if(dataarr.count!=0)
    {
        
        Note *note=dataarr[indexPath.row-1];
        return [cell addCellData:note user:[User defuceUser]];
    }
    return 0;

}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *pengyoucell=@"PengyouCell";
    if(indexPath.row==0)
    {
        UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:pengyoucell];
        if(!cell)
        {
            cell=[[UITableViewCell alloc] init];
            [cell setBackgroundColor:[UIColor colorWithRed:232/255.0 green:232/255.0 blue:232/255.0 alpha:1]];
        }
        
        return cell;
    }
    Note *note=dataarr[indexPath.row-1];
    //[User defuceUser].userId==note.recipientId
    if([User defuceUser].userId==note.recipientId)
    {
        JZFrendeChatHTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:pengyoucell];
        
        if(!cell)
        {
            cell=[[[NSBundle mainBundle] loadNibNamed:@"JZFrendeChatHTableViewCell" owner:self options:nil] objectAtIndex:0];
            cell.viewcontroller=self;
        }
         [tableView setRowHeight:[cell addCellData:note user:self.fuser]];
        return cell;

    }else
    {
        JZHMyChatTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:pengyoucell];
        
        if(!cell)
        {
            cell=[[[NSBundle mainBundle] loadNibNamed:@"JZHMyChatTableViewCell" owner:self options:nil] objectAtIndex:0];
            cell.viewcontroller=self;
        }
        [tableView setRowHeight:[cell addCellData:note user:[User defuceUser]]];
        return cell;

    }
    
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:NO];
    
}



- (IBAction)expressionbut:(UIButton *)sender {
    if(!sender.selected)
    {
        sender.selected=YES;
        self.toolbut.selected=NO;
        [[[UIApplication sharedApplication] keyWindow] endEditing:YES];
        [keyview show];
        //[[[UIApplication sharedApplication] keyWindow] addSubview:keyview];
        [UIView animateWithDuration:0.35 animations:^{
            
            [keyview setFrame:CGRectMake(0, HEIGHT+20-keyview.frame.size.height, keyview.frame.size.width, keyview.frame.size.height)];
             [self.view setCenter:CGPointMake(160, (HEIGHT-keyview.frame.size.height)/2-keyview.frame.size.height/2)];
            [self.toolView setFrame:CGRectMake(0, HEIGHT+20, self.toolView.frame.size.width, self.toolView.frame.size.height)];
            } completion:^(BOOL finished) {
                    [self.toolView setHidden:YES];
               
        }];
        
        
    }
    
   
}
- (IBAction)toolclik:(UIButton *)sender {
    if(!sender.selected)
    {
        self.expression.selected=NO;
        [self.toolView setHidden:NO];
        sender.selected=YES;
        [keyview hidden];
        [[[UIApplication sharedApplication] keyWindow] endEditing:YES];
        [self.toolView setFrame:CGRectMake(0, HEIGHT+20, self.toolView.frame.size.width, self.toolView.frame.size.height)];
        [[[UIApplication sharedApplication] keyWindow] addSubview:self.toolView];
        
        [UIView animateWithDuration:0.35 animations:^{
        
            [self.toolView setFrame:CGRectMake(0, HEIGHT+20-self.toolView.frame.size.height, self.toolView.frame.size.width, self.toolView.frame.size.height)];
            [self.view setCenter:CGPointMake(160, (HEIGHT-self.toolView.frame.size.height)/2-self.toolView.frame.size.height/2+10)];
        }];
        
    }

}
- (void)notkey:(NSNotification *)set
{
   
    CGPoint bpoint=[[[set userInfo] objectForKey:UIKeyboardCenterBeginUserInfoKey] CGPointValue];
    CGPoint epoint=[[[set userInfo] objectForKey:UIKeyboardCenterEndUserInfoKey] CGPointValue];
    if(self.expression.selected && bpoint.y>HEIGHT)
    {
        self.expression.selected=NO;
        [UIView animateWithDuration:0.35 animations:^{
            [self.view setCenter:CGPointMake(160, self.view.frame.size.height/2+(epoint.y-bpoint.y))];
            [keyview hidden];
            NSLog(@"%f",self.view.center.y);
        }];
        
        return;
    }
    
    if(self.toolbut.selected && bpoint.y>HEIGHT)
    {
        self.toolbut.selected=NO;
        [UIView animateWithDuration:0.35 animations:^{
            [self.view setCenter:CGPointMake(160, self.view.frame.size.height/2+(epoint.y-bpoint.y))];
            [UIView animateWithDuration:0.35 animations:^{
                [self.toolView setFrame:CGRectMake(0, HEIGHT+20, self.toolView.frame.size.width, self.toolView.frame.size.height)];
            } completion:^(BOOL finished) {
                [self.toolView setHidden:YES];
            }];

            NSLog(@"%f",self.view.center.y);
        }];
        return;

    }
    if(!self.expression.selected && !self.toolbut.selected)
    {
        
        [UIView animateWithDuration:0.35 animations:^{
            [self.view setCenter:CGPointMake(160, self.view.center.y+(epoint.y-bpoint.y))];
            NSLog(@"%f",self.view.center.y);
        }];
    }
    
}

- (IBAction)clossender:(id)sender
{
    self.playview.hidden=YES;
     [self.table setUserInteractionEnabled:YES];
    [[Rrcorder defule] stoprecorder];
    
}
- (IBAction)poth:(id)sender
{
    
    if(![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]){
        [[[UIAlertView alloc]initWithTitle:@"提示" message:@"当前相册不可用" delegate:Nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil] show];
        return;
    }
    UIImagePickerController *imagecont=[[UIImagePickerController alloc]init];
    imagecont.delegate=self;
    self.toolbut.selected=NO;
    [self presentViewController:imagecont animated:YES completion:^{}];
}
- (IBAction)camar:(id)sender
{
    if(![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
    {
        [[[UIAlertView alloc]initWithTitle:@"提示" message:@"当前相机不可用" delegate:Nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil] show];
        return;
    }
    self.toolbut.selected=NO;
    UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
    [imagePickerController setSourceType:UIImagePickerControllerSourceTypeCamera];
    [imagePickerController setDelegate:self];
    [imagePickerController setAllowsEditing:YES];
    [self presentViewController:imagePickerController animated:YES completion:^{}];
}
#pragma mark 相册 代理方法实现-------------
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    UIImage *img;
    NSLog(@"%@",info);
    if(picker.sourceType == UIImagePickerControllerSourceTypeCamera){
        img=[info objectForKey:UIImagePickerControllerEditedImage];
    }else {
        img=[info objectForKey:UIImagePickerControllerOriginalImage];
    }
    
    [picker dismissViewControllerAnimated:YES completion:^{
        [self updataImage:UIImageJPEGRepresentation(img, 0.5)];
    }];
    
    
}

#pragma mark ------收到消息----
- (void)shoumessage:(NSNotification *)not
{
    [self ToUpdateView];
}

///上传语音
- (void)updataVoid
{
   
   [HttpRequest uploadMessageFile:[palydic objectForKey:@"data"] URL:JZHHTTPURL(@"friendsMessage/uploadMessageFile") key:@"messageVoice"   block:^(id data, HttpReturnCode rerurncode) {
       if(rerurncode==0)
       {
           NSArray *fileNamearr=[[[data objectForKey:@"data"] objectForKey:@"filepath"] componentsSeparatedByString:@"/"];
           NSString *fileName=[fileNamearr objectAtIndex:fileNamearr.count-1];
           [[Rrcorder defule] saveAudioName:fileName data:[palydic objectForKey:@"data"]];
           [self.table setUserInteractionEnabled:YES];
           [self senderMessge:[[data objectForKey:@"data"] objectForKey:@"filepath"] tyep:VOICE];
       }
   }];
    
}

///上传图片
- (void)updataImage:(NSData *)imageData
{
    [HttpRequest uploadMessageFile:imageData URL:JZHHTTPURL(@"friendsMessage/uploadMessageFile") key:@"messageImage"  block:^(id data, HttpReturnCode rerurncode) {
        if(rerurncode==0)
        {
            NSArray *fileNamearr=[[[data objectForKey:@"data"] objectForKey:@"filepath"] componentsSeparatedByString:@"/"];
            NSString *fileName=[fileNamearr objectAtIndex:fileNamearr.count-1];
            [ImageCache saveImage:fileName imageData:imageData];
            [self.table setUserInteractionEnabled:YES];
            [self senderMessge:[[data objectForKey:@"data"] objectForKey:@"filepath"] tyep:IMAGE];
        }
    }];

}

#pragma mark -----名片推荐提示框代理-----
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if(buttonIndex==0)
    {
       
        
    }else
    {
        OtherUsers *ouser=(OtherUsers *)self.recommend;
        NSDictionary *dic=[[NSDictionary alloc] initWithObjectsAndKeys:[NSNumber numberWithInt:ouser.userId],@"id",ouser.name,@"name",ouser.userHeadImage,@"headimage", nil];
        NSData *jsondata=[NSJSONSerialization dataWithJSONObject:dic options:NSJSONWritingPrettyPrinted error:nil];
        NSString *json=[[NSString alloc]initWithData:jsondata encoding:NSUTF8StringEncoding];
        [self senderMessge:json tyep:BC];
        self.recommend=nil;
    }
}
- (IBAction)pusmp:(id)sender
{
    [self.navigationController pushViewController:[[JZHContactsViewController alloc] initIsSelectNote:self] animated:YES];
}
@end
